<template>
    <div class="template-form-Lu">
        <a-modal
            title="干部职工加班值班申请"
            :visible="applicationFormVisible"
            :maskClosable="false"
            :closable="true"
            :destroyOnClose="true"
            width="100%"
            :dialog-style="{ margin: '0 auto' }"
            wrapClassName="applicationModal-form-fullmodal-Lu"
            @cancel="closeVisible">
            <div class="applicationModal-div-box-Lu">
                <div class="tabs-card-edit-box">
                    <a-tabs type="card" v-model:activeKey="summaryActiveKey" @change="summaryActiveChange">
                        <a-tab-pane key="申请表" tab="申请表"></a-tab-pane>
                        <a-tab-pane key="流转记录" tab="流转记录"></a-tab-pane>
                    </a-tabs>
                </div>
                <div  class="tab-box-v1">
                    <div v-if="summaryActiveKey == '申请表'" style="width: 70%;margin: 0 auto;padding-top: 30px;padding-bottom: 30px;">
                        <a-spin :spinning="spinning">
                            <a-button class="blue-btn" @click="printClick('加班',formState,qmImgList)" v-if="linkName == '我的已办'">打印</a-button>
                            <a-form :form="aform" ref="form" class="internalControl-reimbursement-model-form-box">
                                <a-descriptions bordered style="width: 100%;">
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='申请'">*</span>
                                            加班/值班开始日期
                                        </span>
                                        <a-form-item ref="fjbzbksrq" prop="fjbzbksrq" class="zm-form-model">
                                            <a-input-group compact v-if="linkName=='申请' || linkName == '数据修订'">
                                                <a-date-picker
                                                    style="width: 60%"
                                                    @change="rqChange1"
                                                    type="date"
                                                    placeholder=""
                                                    v-decorator="[
                                                        'fjbzbksrq', {initialValue:formState.fjbzbksrq,rules: rules.fjbzbksrq}]"
                                                    />
                                                <a-select
                                                    style="width: 40%"
                                                    default-value="08:00"
                                                    v-model="formState.fjbzbkssj"
                                                    @change="timeChange">
                                                    <a-select-option value="08:00">
                                                        08:00
                                                    </a-select-option>
                                                    <a-select-option value="12:00">
                                                        12:00
                                                    </a-select-option>
                                                    <a-select-option value="18:00">
                                                        18:00
                                                    </a-select-option>
                                                </a-select>
                                            </a-input-group>
                                            <span v-else>{{ moment(formState.fjbzbksrq).format('YYYY-MM-DD') + ' ' +  formState.fjbzbkssj}}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='申请'">*</span>
                                            加班/值班结束日期
                                        </span>
                                        <a-form-item ref="fjbzbjsrq" prop="fjbzbjsrq" class="zm-form-model">
                                            <a-input-group compact v-if="linkName=='申请' || linkName == '数据修订'">
                                                <a-date-picker
                                                    style="width: 60%"
                                                    @change="rqChange2"
                                                    type="date"
                                                    placeholder=""
                                                    v-decorator="[
                                                        'fjbzbjsrq', {initialValue:formState.fjbzbjsrq,rules: rules.fjbzbjsrq}]"
                                                />
                                                <a-select
                                                    style="width: 40%"
                                                    default-value="18:00"
                                                    v-model="formState.fjbzbjssj"
                                                    @change="timeChange">
                                                    <a-select-option value="08:00">
                                                        08:00
                                                    </a-select-option>
                                                    <a-select-option value="12:00">
                                                        12:00
                                                    </a-select-option>
                                                    <a-select-option value="18:00">
                                                        18:00
                                                    </a-select-option>
                                                </a-select>
                                            </a-input-group>
                                            <span v-else>{{ moment(formState.fjbzbjsrq).format('YYYY-MM-DD') + ' ' +  formState.fjbzbjssj}}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='申请'">*</span>
                                            总计时长
                                        </span>
                                        <a-form-item ref="fjbzbsc" prop="fjbzbsc" class="zm-form-model">
                                            <span v-if="formState.fjbzbsc">共 {{ formState.fjbzbsc }} 天</span>
                                            <span v-else>自动计算，无需填写</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='申请'">*</span>
                                            加班值班理由
                                        </span>
                                        <a-form-item ref="fjbzbsy" prop="fjbzbsy" class="zm-form-model">
                                            <a-textarea
                                                v-if="linkName=='申请' || linkName == '数据修订'"
                                                v-model="formState.fjbzbsy"
                                                placeholder="请输入加班值班理由:"
                                                :auto-size="{ minRows: 2}"
                                                v-decorator="[
                                                    'fjbzbsy', {initialValue:formState.fjbzbsy,rules: rules.fjbzbsy}]"
                                            />
                                            <span v-else>{{ formState.fjbzbsy }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('科室审批').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('科室审批').hjmc">*</span>
                                            科室负责人意见
                                        </span>
                                        <a-form-item ref="fksspr" prop="fksspr" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('科室审批').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsReffksspr"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('加班值班',formState.fksspr,'fksspr')"
                                                    v-decorator="[
                                                        'fksspr', { initialValue:formState.fksspr, rules: rules.fksspr}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.fkssprqmsj)"
                                                        :default-value="moment(formState.fkssprqmsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'fkssprqmsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.fksspr }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('科室审批')" :src="getUrl('科室审批')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fkssprqm }}</span>
                                                    <span>{{ formState.fkssprqmsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('分管审批').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('分管审批').hjmc">*</span>
                                            分管领导意见
                                        </span>
                                        <a-form-item ref="fksspr" prop="fksspr" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('分管审批').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsRefffgspr"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('加班值班',formState.ffgspr,'ffgspr')"
                                                    v-decorator="[
                                                        'ffgspr', { initialValue:formState.ffgspr, rules: rules.ffgspr}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.ffgsprqmsj)"
                                                        :default-value="moment(formState.ffgsprqmsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'ffgsprqmsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.ffgspr }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('分管审批')" :src="getUrl('分管审批')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.ffgsprqm }}</span>
                                                    <span>{{ formState.ffgsprqmsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('单位领导审批').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('单位领导审批').hjmc">*</span>
                                            单位领导意见
                                        </span>
                                        <a-form-item ref="fksspr" prop="fksspr" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('单位领导审批').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsReffdwldspr"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('加班值班',formState.fdwldspr,'fdwldspr')"
                                                    v-decorator="[
                                                        'fdwldspr', { initialValue:formState.fdwldspr, rules: rules.fdwldspr}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.fdwldsprqmsj)"
                                                        :default-value="moment(formState.fdwldsprqmsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'fdwldsprqmsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.fdwldspr }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('单位领导审批')" :src="getUrl('单位领导审批')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fdwldsprqm }}</span>
                                                    <span>{{ formState.fdwldsprqmsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('加班办理').blzt == '已办'">
                                        <span slot="label" class="descriptions-label-slot">
                                            加班/值班办理
                                        </span>
                                        <a-form-item ref="fjbzbblr" prop="fjbzbblr" class="zm-form-model">
                                            <div style="width: 100%;" v-if="linkName=='数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsReffjbzbblr"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('加班值班',formState.fjbzbblr,'fjbzbblr')"
                                                    v-decorator="[
                                                        'fjbzbblr', { initialValue:formState.fjbzbblr, rules: rules.fjbzbblr}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.fjbzbblrqmsj)"
                                                        :default-value="moment(formState.fjbzbblrqmsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'fjbzbblrqmsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.fjbzbblr }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('加班办理')" :src="getUrl('加班办理')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fjbzbblrqm }}</span>
                                                    <span>{{ formState.fjbzbblrqmsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                </a-descriptions>
                            </a-form>
                        </a-spin>
                    </div>
                    <div v-if="summaryActiveKey == '流转记录'" style="padding-top: 30px;">
                        <transferRecords
                            ref="transferRecordsRef"
                            :config="circulationDataTableConfig"
                            @getCirculationQmImg="getCirculationQmImg"/>
                    </div>
                </div>
            </div>
            <template slot="footer">
                <div v-if="linkName == '我的已办'">
                    <a-button class="blue-btn" @click="closeVisible">关闭</a-button>
                </div>
                <div v-else-if="linkName == '加班办理'">
                    <a-button class="blue-btn" @click="onSubmit('提交')">确认加班值班</a-button>
                </div>
                <div v-else-if="linkName == '数据修订'">
                    <a-button class="blue-btn" @click="updataData">确认修订</a-button>
                </div>
                <div v-else>
                    <a-button @click="onSave('保存')">
                        保存
                    </a-button>
                    <a-button class="blue-btn" @click="onSubmit('提交')">
                        提交
                    </a-button>
                    <a-button v-if="linkName !== '申请'" class="red-btn" @click="returnClick">
                        退回
                    </a-button>
                </div>
            </template>
        </a-modal>
        <printModal ref="printModalRef" />
    </div>
</template>
<script>
import {
    flowJkPage,
    initBzFlow,
    saveFlow,
    submitFlow,
    queryJobByJobId,
    returnUpperzdyFlowJob,
    getMoreUserSignLinkList,
    pidgetlchj,
    editFuntion,
} from './service/index'
import assessCheckApi from './service/api.js'
import transferRecords from '../modal/transferRecords'
import printModal from '../modal/printModal'
import moment from 'moment'
export default {
    components: {
        transferRecords,
        printModal
    },
    data() {
        return {
            moment:moment,
            applicationFormVisible: false,
            summaryActiveKey: '申请表',
            aform:this.$form.createForm(this, { name: 'aform' }),
            formState: {
                fjbzbjssj: "18:00",
                fjbzbkssj: "08:00",
            },
            circulationDataTableConfig: {
                api: assessCheckApi.flowJkPage,
                rowId: 'id',
                urlType: true,
                paramet:{
                    oaid: ''
                }
            },
            rules:{
                fccdd: [{
                    required: true,
                    message: '请输入出差地点',
                    trigger: 'blur',
                }],
                fjbzbksrq: [{
                    type: 'object',
                    required: true,
                    message: '请选择加班/值班开始日期',
                    trigger: 'blur',
                }],
                fjbzbjsrq: [{
                    type: 'object',
                    required: true,
                    message: '请选择加班/值班结束日期',
                    trigger: 'blur',
                }],
                fjbzbsy: [{
                    required: true,
                    message: '请输入加班值班理由',
                    trigger: 'blur',
                }],
                fksspr: [
                    { required: true, message: '请输入本科（室）意见', trigger: 'blur' }
                ],
                fbgspcyj: [
                    { required: true, message: '请输入办公室意见', trigger: 'blur' }
                ],
                ffgspr: [
                    { required: true, message: '请输入中心分管领导意见', trigger: 'blur' }
                ],
                fdwldspr: [
                    { required: true, message: '请输入中心主要领导意见', trigger: 'blur' }
                ],
            },
            qmImgList: [],
            displayList: [],
            linkName: '申请',
            spinning: false,
        }
    },
    mounted() {
        // this.circulationDataTableConfig.paramet.oaid = '96db3fccad0245df878468d4339f9e5e'
        this.$refs.reviewOpinionsRef= Date.now()
    },
    methods: {
        getInitData(){
            this.formState = {}
            this.formState = {
                fjbzbjssj: "18:00",
                fjbzbkssj: "08:00",
            }
        },
        getData(val){
            if(val){
                this.summaryActiveKey = '申请表'
                this.linkName = val.hjmc
                this.formState = {}
                this.formState = {
                    ...val.oaMap,
                    jobid: val.jobMap?val.jobMap.id:''
                }
                this.formState.fjbzbksrq = val.oaMap.fjbzbksrq?moment(val.oaMap.fjbzbksrq):null
                this.formState.fjbzbjsrq = val.oaMap.fjbzbjsrq?moment(val.oaMap.fjbzbjsrq):null
                this.circulationDataTableConfig.paramet.oaid = this.formState.id
                this.qmImgList = []
                this.displayList = []
                this.getDisplayList()
            }
        },
        getDisplayList(){
            pidgetlchj({pid:this.formState.id}).then((res) => {
                let arr1 = res.result
                this.displayList = []
                this.displayList = res.result

                if(this.linkName == '数据修订'){
                    const index = this.displayList.findIndex((item) => item.blzt == '待办');
                    if (index !== -1) {
                        this.displayList.splice(index, 1);
                    }
                    //console.log('this.displayList',this.displayList)
                }

                arr1.forEach(async item => {
                    if(item.blrid && item.blzt!=='待办'){
                        let resa = await getMoreUserSignLinkList({ids:item.blrid})
                        if(resa.success && resa.result.length){
                            if(resa.result[0].signLink == ''){
                                // //console.log('没有获得图片 signLink == 0')
                                this.qmImgList.push({
                                    hjmc: item.hjmc,
                                    url: null
                                })
                            } else {
                                this.qmImgList.push({
                                    hjmc: item.hjmc,
                                    url: resa.result[0].signLink+'&aa='+Date.now()
                                })
                                // //console.log('获得的签名图片列表',this.qmImgList)
                            }
                        } else {
                            // //console.log('没有获得图片')
                        }
                    } else {}
                })
                // //console.log('最终获得的签名图片列表---',this.qmImgList)
            })
        },
        closeVisible(){
            this.applicationFormVisible = false
            this.$emit('success')
        },
        summaryActiveChange(val){
            //console.log(val)
        },
        rqChange1(val){
            this.formState.fjbzbksrq = val
            this.timeChange()
        },
        rqChange2(val){
            this.formState.fjbzbjsrq = val
            this.timeChange()
        },
        timeChange(){
            //console.log('=============',this.formState.fjbzbksrq,this.formState.fjbzbjsrq)
            if(this.formState.fjbzbksrq !== null && this.formState.fjbzbjsrq !==null){
                let start = new Date(Date.parse(this.formState.fjbzbksrq));
                let end = new Date(Date.parse(this.formState.fjbzbjsrq));
                let diff = end.getTime() - start.getTime();// 两个日期相差的毫秒数
                let days = Math.floor(diff / (1000 * 60 * 60 * 24))
                let time1 = Number(this.formState.fjbzbkssj.substr(0,2))
                let time2 = Number(this.formState.fjbzbjssj.substr(0,2))
                let time3 = time1 + time2
                let time = 0
                if(days == 0){
                    if(this.formState.fjbzbkssj == '08:00'){
                        if(this.formState.fjbzbjssj == '08:00'){
                        this.$message.warning('当前选择天数为0，请重新选择！')
                        } else if(this.formState.fjbzbjssj == '12:00'){
                        time = 0.5
                        } else if(this.formState.fjbzbjssj == '18:00'){
                        time = 1
                        }
                    } else if(this.formState.fjbzbkssj == '12:00'){
                        if(this.formState.fjbzbjssj == '08:00'){
                        this.$message.warning('当前选择天数为0，请重新选择！')
                        } else if(this.formState.fjbzbjssj == '12:00'){
                        time = 0
                        } else if(this.formState.fjbzbjssj == '18:00'){
                        time = 0.5
                        }
                    } else if(this.formState.fjbzbkssj == '18:00'){
                        if(this.formState.fjbzbjssj == '08:00'){
                        this.$message.warning('当前选择天数为0，请重新选择！')
                        } else if(this.formState.fjbzbjssj == '12:00'){
                        this.$message.warning('当前选择天数为0，请重新选择！')
                        } else if(this.formState.fjbzbjssj == '18:00'){
                        time = 0
                        }
                    }
                } else {
                    if(this.formState.fjbzbkssj == '08:00'){
                        if(this.formState.fjbzbjssj == '08:00'){
                        time = 0
                        } else if(this.formState.fjbzbjssj == '12:00'){
                        time = 0.5
                        } else if(this.formState.fjbzbjssj == '18:00'){
                        time = 1
                        }
                    } else if(this.formState.fjbzbkssj == '12:00'){
                        if(this.formState.fjbzbjssj == '08:00'){
                        time = -0.5
                        } else if(this.formState.fjbzbjssj == '12:00'){
                        time = 0
                        } else if(this.formState.fjbzbjssj == '18:00'){
                        time = 0.5
                        }
                    } else if(this.formState.fjbzbkssj == '18:00'){
                        if(this.formState.fjbzbjssj == '08:00'){
                        if(days == 1){
                            this.$message.warning('当前选择天数为0，请重新选择！')
                            time = -1
                        } else {
                            time = 0
                        }
                        } else if(this.formState.fjbzbjssj == '12:00'){
                        if(days == 1){
                            time = -0.5
                        } else {
                            time = 0
                        }
                        } else if(this.formState.fjbzbjssj == '18:00'){
                        time = 0
                        }
                    }
                }
                let data = days + time
                if(data <= 0){
                this.$message.warning('加班值班天数需大于0，当前选择天数为'+data+'天，请重新选择')
                this.formState.fjbzbsc = ''
                return
                }
                this.formState.fjbzbsc = data
                //console.log(this.formState.fjbzbsc)
            } else {
                this.formState.fjbzbsc = ''
            }
        },
        getCirculationQmImg(item1,item2){
            //console.log('-----?????-----',item1,item2)
            this.qmImgList = []
            this.displayList = []
            this.qmImgList = item1
            this.displayList = [...item2]
            //console.log('111111111',this.qmImgList)
            //console.log('222222222',this.displayList)
        },
        getUrl(hjmcName){
            let url = ''
            // //console.log('没有？？？',this.qmImgList)
            this.qmImgList.forEach(item => {
                // //console.log(hjmcName,item)
                if(item.hjmc == hjmcName){
                    url = item.url
                }
            })
            // //console.log(hjmcName,url)
            return url
        },
        descriptionsData(hjmc){
            let data = {}
            this.displayList.forEach(item => {
                // //console.log('descriptionsData000',hjmc,item)
                if(item.hjmc == hjmc){
                    data = {...item}
                }
            })
            // //console.log('descriptionsData',data)
            return data
        },
        getInputOpinion(val,valueData){
            //console.log(val,valueData)
            let data = this.formState
            data[valueData.hjmc] = val
            this.aform.setFieldsValue({
                fksspr: this.formState.fksspr,
                fbgspcyj: this.formState.fbgspcyj,
                ffgspr: this.formState.ffgspr,
                fdwldspr: this.formState.fdwldspr
            });
        },
        opinions(val1,val2,val3){
            //console.log(val1,val2,val3)
            this.$refs[`reviewOpinionsRef${val3}`].getData({opinionType:val1,oldVal:val2,valueData:{hjmc:val3}})
        },
        onSave(){
            let data = {}
            let sdata = {
                jobid: this.formState.jobid,
                oaid: this.formState.id,
                map: {},
                opinion: '',
            }
            if(this.linkName == '申请'){
                data = {
                    fjbzbsy: this.formState.fjbzbsy,
                    fjbzbksrq: moment(this.formState.fjbzbksrq).format('YYYY-MM-DD'),
                    fjbzbjsrq: moment(this.formState.fjbzbjsrq).format('YYYY-MM-DD'),
                    fjbzbkssj: this.formState.fjbzbkssj,
                    fjbzbjssj: this.formState.fjbzbjssj,
                    fjbzbsc: this.formState.fjbzbsc,
                    id: this.formState.id?this.formState.id:''
                }
                sdata.map = {
                    ...data
                }
                this.formState.id?this.saveFlowFuntion(sdata):this.initBzFlowFuntion(data)
            } else if(this.linkName == '科室审批'){
                sdata.map = {
                    fkssprqm: this.formState.fkssprqm,
                    fkssprqmsj: this.formState.fkssprqmsj,
                    fksspr: this.formState.fksspr,
                }
                sdata.opinion = this.formState.fksspr,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '分管审批'){
                sdata.map = {
                    ffgspr: this.formState.ffgspr,
                    ffgsprqm: this.formState.ffgsprqm,
                    ffgsprqmsj: this.formState.ffgsprqmsj,
                }
                sdata.opinion = this.formState.ffgspr,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '单位领导审批'){
                sdata.map = {
                    fdwldspr: this.formState.fdwldspr,
                    fdwldsprqm: this.formState.fdwldsprqm,
                    fdwldsprqmsj: this.formState.fdwldsprqmsj,
                }
                sdata.opinion = this.formState.fdwldspr,
                this.saveFlowFuntion(sdata)
            }
        },
        onSubmit(){
            this.aform.validateFields((err, values) => {
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要提交吗?',
                        onOk() {
                            let data = {
                                jobid: that.formState.jobid,
                                oaid: that.formState.id,
                                map: {},
                                opinion: '',
                            }
                            if(that.linkName == '申请'){
                                data.map = {
                                    fjbzbsy: that.formState.fjbzbsy,
                                    fjbzbksrq: moment(that.formState.fjbzbksrq).format('YYYY-MM-DD'),
                                    fjbzbjsrq: moment(that.formState.fjbzbjsrq).format('YYYY-MM-DD'),
                                    fjbzbkssj: that.formState.fjbzbkssj,
                                    fjbzbjssj: that.formState.fjbzbjssj,
                                    fjbzbsc: that.formState.fjbzbsc,
                                    id: that.formState.id?that.formState.id:'',
                                    fsffqlc: that.formState.id?'':'是',
                                }
                                that.formState.id?that.submitFlowFuntion(data):that.initBzFlowFuntion(data.map,'1')
                            } else if(that.linkName == '科室审批'){
                                data.map = {
                                    fkssprqm: that.formState.fkssprqm,
                                    fkssprqmsj: that.formState.fkssprqmsj,
                                    fksspr: that.formState.fksspr,
                                }
                                data.opinion = that.formState.fksspr,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '办公室审核'){
                                data.map = {
                                    fbgspcyj: that.formState.fbgspcyj,
                                    fbgspcyjr: that.formState.fbgspcyjr,
                                    fbgspcyjsj: that.formState.fbgspcyjsj
                                }
                                data.opinion = that.formState.fbgspcyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '分管审批'){
                                data.map = {
                                    ffgspr: that.formState.ffgspr,
                                    ffgsprqm: that.formState.ffgsprqm,
                                    ffgsprqmsj: that.formState.ffgsprqmsj,
                                }
                                data.opinion = that.formState.ffgspr,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '单位领导审批'){
                                data.map = {
                                    fdwldspr: that.formState.fdwldspr,
                                    fdwldsprqm: that.formState.fdwldsprqm,
                                    fdwldsprqmsj: that.formState.fdwldsprqmsj,
                                }
                                data.opinion = that.formState.fdwldspr,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '加班办理'){
                                data.map = {
                                    fjbzbblr: '确认加班值班',
                                    fjbzbblrqm: that.formState.fjbzbblrqm,
                                    fjbzbblrqmsj: that.formState.fjbzbblrqmsj,
                                }
                                data.opinion = '确认加班值班',
                                that.submitFlowFuntion(data)
                            }
                        },
                        onCancel() {},
                    });
                }
            })
        },
        initBzFlowFuntion(data,type){
            initBzFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.formState = {}
                    this.formState = {
                        ...res.result.oaMap,
                        jobid: res.result.jobMap.id
                    }
                    this.formState.fjbzbksrq = moment(this.formState.fjbzbksrq)
                    this.formState.fjbzbjsrq = moment(this.formState.fjbzbjsrq)
                    if(type){
                        this.closeVisible()
                    }
                } else {
                    this.$message.warning(res.message)
                }
                this.loading = false
            })
        },
        saveFlowFuntion(data){
            this.spinning = true
            saveFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                } else {
                    this.$message.warning(res.message)
                }
                this.spinning = false
            })
        },
        submitFlowFuntion(data){
            this.spinning = true
            submitFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.warning(res.message)
                }
                this.spinning = false
            })
        },
        // 退回
        returnClick(){
            this.aform.validateFields((err, values) => {
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要退回吗?',
                        onOk() {
                            that.spinning = true
                            queryJobByJobId({jobid:that.formState.jobid}).then(res => {
                                let list = res.result.jobHistoryList
                                let slist = list.filter(item => item.fhjmc == '申请')
                                const sortedDates = slist.sort((a, b) => new Date(b) - new Date(a));
                                that.returnFuntion(that.formState.jobid,sortedDates[slist.length - 1].id)
                            })
                        },
                        onCancel() {},
                    })
                }
            })
        },
        returnFuntion(jobid,ids){
            let returnStr = ''
            if(this.linkName == '申请'){
                returnStr = this.formState.fksshyj
            } else if(this.linkName == '科室审批'){
                returnStr = this.formState.fksspr
            } else if(this.linkName == '分管审批'){
                returnStr = this.formState.ffgspr
            } else if(this.linkName == '单位领导审批'){
                returnStr = this.formState.fdwldspr
            }
            let data = {
                jobid: jobid,
                opinion: returnStr,
                shjid: ids,
                lcmbbm: '',
                smgflag: '',
                smsContent: '',
            }
            returnUpperzdyFlowJob(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.error(res.message)
                }
                this.spinning = false
            })
        },
        printClick(type,value,qmValue){
            this.$refs.printModalRef.modalClick(type,value,qmValue)
        },
        yjTimeChange(val,name){
            let data = this.formState
            data[name] = moment(val).format('YYYY-MM-DD HH:mm:ss')
        },
        updataData(){
            var that = this
            that.$confirm({
                title: '您确定修改当前表单数据吗?',
                onOk() {
                    let data = {
                        id: that.formState.id,
                        fjbzbsy: that.formState.fjbzbsy,
                        fjbzbksrq: moment(that.formState.fjbzbksrq).format('YYYY-MM-DD'),
                        fjbzbjsrq: moment(that.formState.fjbzbjsrq).format('YYYY-MM-DD'),
                        fjbzbkssj: that.formState.fjbzbkssj,
                        fjbzbjssj: that.formState.fjbzbjssj,
                        fjbzbsc: that.formState.fjbzbsc,
                        fkssprqm: that.formState.fkssprqm,
                        fkssprqmsj: that.formState.fkssprqmsj,
                        fksspr: that.formState.fksspr,
                        fbgspcyj: that.formState.fbgspcyj,
                        fbgspcyjr: that.formState.fbgspcyjr,
                        fbgspcyjsj: that.formState.fbgspcyjsj,
                        ffgspr: that.formState.ffgspr,
                        ffgsprqm: that.formState.ffgsprqm,
                        ffgsprqmsj: that.formState.ffgsprqmsj,
                        fdwldspr: that.formState.fdwldspr,
                        fdwldsprqm: that.formState.fdwldsprqm,
                        fdwldsprqmsj: that.formState.fdwldsprqmsj,
                        fjbzbblr: that.formState.fjbzbblr,
                        fjbzbblrqm: that.formState.fjbzbblrqm,
                        fjbzbblrqmsj: that.formState.fjbzbblrqmsj,
                    }
                    //console.log(data)
                    that.spinning = true
                    editFuntion(data).then(res => {
                        if(res.code == 200){
                            that.$message.success(res.message)
                        } else {
                            that.$message.warning(res.message)
                        }
                        that.spinning = false
                    })
                },
                onCancel() {
                    //console.log('Cancel');
                },
            });
        },
    }
}
</script>
<style>
@import url('../css/oaLess.css');
</style>
